/*******************************************************************
 *         Advanced 3D Game Programming using DirectX 8.0
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *   Title: matrix4.h
 *    Desc: Declaration for a 4x4 homogenous matrix class
 *          
 * copyright (c) 2001 by Peter A Walsh and Adrian Perez
 * See license.txt for modification and distribution information
 ******************************************************************/

#ifndef _MATRIX4_H
#define _MATRIX4_H

#include <math.h>

struct matrix4 
{

	/**
	 * we're using m[y][x] as our notation.
	 */
    union 
	{
        struct 
		{
            float	_11, _12, _13, _14;
            float	_21, _22, _23, _24;
            float	_31, _32, _33, _34;
            float	_41, _42, _43, _44;
        };
        float	m[4][4];
    };

	/**
	 * justification for a function this ugly:
	 * provides an easy way to initialize static matrix variables 
	 * like base matrices for bezier curves and the identity
	 */
	matrix4(
		float in11, float in12, float in13, float in14,
        float in21, float in22, float in23, float in24,
        float in31, float in32, float in33, float in34,
        float in41, float in42, float in43, float in44 )
	{
        _11 = in11; _12 = in12; _13 = in13; _14 = in14;
        _21 = in21; _22 = in22; _23 = in23; _24 = in24;
        _31 = in31; _32 = in32; _33 = in33; _34 = in34;
        _41 = in41; _42 = in42; _43 = in43; _44 = in44;
	}

	matrix4()
	{
		// Do nothing.  
	}


	/**
	 * Make the matrix the identity matrix
	 */
	void MakeIdent();

	/**
	 * Rotate an existing matrix by a given yaw, pitch,
	 * and roll.
	 */
	void Rotate( float yaw, float pitch, float roll );

	static const matrix4 Identity;
};



//==========--------------------------  matrix4 operators

/**
 * returns matrix4*matrix4
 * not inlined due to the size.
 */
matrix4 operator*(matrix4 const &a, matrix4 const &b);
void MatMult( const matrix4 &a, const matrix4& b, matrix4* result );



#endif //_MATRIX4_H